<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\GrFeedback;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class GrFeedbackController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new GrFeedback(), function (Grid $grid) {
            $grid->column('id')->sortable();
//            $grid->column('user_id');
            $grid->column('tel');
            $grid->column('feed_type');
            $grid->column('content');
            $grid->column('picture')->display(function ($pictures){
                return json_decode($pictures,true);
            })->image('',100,100);
            $grid->column('email');
            $grid->column('order_num');
            $grid->column('state')->switch();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new GrFeedback(), function (Show $show) {
            $show->field('id');
//            $show->field('user_id');
            $show->field('tel');
            $show->field('feed_type');
            $show->field('content');
            $show->field('picture');
            $show->field('email');
            $show->field('order_num');
            $show->field('state');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new GrFeedback(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('tel');
            $form->text('feed_type');
            $form->text('content');
            $form->text('picture');
            $form->text('email');
            $form->text('order_num');
            $form->switch('state')
                ->customFormat(function ($v) {
                    return $v == '打开' ? 1 : 0;
                })
                ->saving(function ($v) {
                    return $v ? '1' : '0';
                });

        });
    }
}
